<template>
	<view class="content">
		<form @submit="formSubmit">
			<view class="form">
				<view class="formch">
					<view>姓名</view>
					<!-- <input name="input" placeholder="请填写" style="text-align: right;" /> -->
					<view>{{ list.nickname }}</view>
				</view>
				<view class="xian"></view>
				<view class="formch">
					<view>手机号</view>
					<view>{{ list.mobile }}</view>
					<!-- <input name="input" placeholder="请填写" style="text-align: right;" /> -->
				</view>
				<view class="xian"></view>
				<view class="formch">
					<view>亩数</view>
					<view>{{ list.landarea }}</view>
				</view>
				<view class="xian"></view>
				<view class="formch">
					<view>联系人地址</view>
					<view>{{ list.city }}-{{ list.area }}-{{ list.street }}</view>
					<!-- <input name="input" placeholder="请填写" style="text-align: right;" /> -->
				</view>
			</view>
			<view>
				<button v-if="subdata" @click="queding" class="button">确定</button>
				<button v-if="status == '0'" style="background-color: #ddd;" class="button">发布中</button>
				<button v-if="status == '1'" class="button">待确认</button>
				<button v-if="status == '2'" class="button">已出租</button>
				<!-- <button v-if="status=='0'" @click="bianji" class="button">发布中</button>
		   <button v-if="status=='1'" @click="bianji" class="button">待确认</button>
		   <button v-if="status=='2'" @click="chuzu" class="button">已出租</button> -->
				<view class="changeRadio">
					<label class="radio"  style="transform:scale(0.6)"><radio color="#3FC377" value="" :checked="show" @click="checkbox()" /></label>
					<view style="margin-left: -10rpx;" @click="goOut()">《默认合同》</view>
				</view>
			</view>
			<!--  <view v-if="status=='1'" class="bottom">
          <view>
            <button  @click="sureout(0)">重新出租</button>
          </view>
          <view>
            <button @click="sureout(2)">确认出租</button>
          </view>
        </view>
       -->
		</form>

		<!-- <view v-if="popupdata" class="popup1"></view>
    <view v-if="popupdata" class="popup">
    	<view v-if="outdata" class="setpop">
    		确认重新出租？ 
    	</view>
      <view v-if="!outdata" class="setpop">
      	确认出租？ 
      </view>
      <view class="setpopch">
        <view class="quding" @click="closes">
        	取消
        </view>
        <view class="quding" @click="lquedong">
        	确定
        </view>
      </view>
      
    </view> -->
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: {},
			input: '',
			popupdata: false,
			outdata: false,
			subdata: true,
			subdata2: false,
			id: 0,
			status: '100',
			show: false
		};
	},
	// computed: {
	// 	...mapState({
	// 		user: state => state.user,//个人用户信息
	// 	})
	// },
	onLoad() {
		this.getdata();
	},
	onShow() {
		// this.getdata()
	},
	methods: {
		goOut() {
			uni.navigateTo({
				url: '/pages/me/outearth/out_xieyi'
			});
		},
		checkbox() {
			this.show = !this.show;
		},
		bianji() {
			this.$u.toast('等待租用');
		},
		chuzu() {
			this.$u.toast('出租中');
		},
		async queding() {
			if (this.show == false) {
				this.$u.toast('请勾选同意默认合同');
				return;
			}
			let address = this.list.city + this.list.area + this.list.street;
			let token = this.list.token;
			let username = this.list.nickname;
			let mobile = this.list.mobile;
			let res = await this.$http.post('/api/index/publish_rent', { token: token, address: address, username: username, mobile: mobile });
			this.subdata = false;
			//this.$u.toast('操作成功');
			this.getdata();
		},
		async getstatus(id) {
			let res = await this.$http.post('/api/index/get_my_rent', { id: id });
			this.status = res.data.data.status;
			// console.log('getstatus');
			// console.log(this.status);
		},
		async getdata() {
			let res = await this.$http.post('/api/user/userinfo');
			this.list = res.data.data.userinfo;
			if (this.list.isrent == 0) {
				this.subdata = true;
				// this.status=10;
			} else {
				this.subdata = false;
				this.id = this.list.isrent;
				// console.log('getdata');
				// console.log(this.id);
				this.getstatus(this.id);
			}
		},
		closes() {
			this.popupdata = false;
		},
		formSubmit() {
			//console.log('0000');
		},
		// sureout(data){
		//   if(data==0){
		//     this.popupdata = true;
		//     this.outdata=true;
		//   }else{
		//     this.popupdata = true;
		//     this.outdata=false;
		//   }
		// },
		async lquedong() {
			if (this.outdata == true) {
				let res = await this.$http.post('/api/index/set_rent', { id: this.id, status: 0 });
				this.$u.toast('操作成功');
				this.popupdata = false;
				this.getdata();
			} else {
				let res = await this.$http.post('/api/index/set_rent', { id: this.id, status: 2 });
				this.$u.toast('操作成功');
				this.popupdata = false;
				this.getdata();
			}
		}
	}
};
</script>

<style scoped lang="scss">
.content {
	background-color: #f8f8f8;
	width: 100%;
	min-height: 100vh;
	padding: 15px;
	font-size: 15px;
}
.form {
	background-color: white;
	padding: 21px 16px 19.5px 15.5px;
	border-radius: 10px;
}
.formch {
	/* background-color: white; */
	display: flex;
	justify-content: space-between;
}
.xian {
	height: 0.5px;
	background: rgba(0, 0, 0, 0.1);
	margin: 20px 0;
}
.button {
	width: 268px;
	line-height: 44px;
	background-color: #3fc377;
	color: #ffffff;
	margin-top: 26.5px;
	font-size: 15px;
	margin-bottom: 20rpx;
}
.bottom {
	display: flex;
	padding: 0 39px;
	justify-content: space-between;
}
.bottom button {
	width: 125px;
	line-height: 44px;
	background-color: #3fc377;
	color: #ffffff;
	margin-top: 26.5px;
	font-size: 15px;
}
.changeRadio{
	width: 250rpx;
	height: 40rpx;
	margin: 30rpx auto;
	display: flex;
	align-items: center;
	.radio{
		
	}
}
.popup1 {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: #000;
	opacity: 0.7;
	filter: alpha(opacity=50);
	z-index: 100;
}

.popup {
	position: absolute;
	top: 200px;
	left: 38px;
	width: 291px;
	/* height:564upx; */
	background: #fff;
	margin-left: 12upx;
	border-radius: 10upx;
	font-weight: 600;
	z-index: 102;
}
.setpop {
	text-align: center;
	margin-top: 39.5px;
	margin-bottom: 46px;
	font-size: 18px;
}
.setpopch {
	display: flex;
	justify-content: space-between;
	padding: 0 12px 13.5px;
}
.setpopch view {
	width: 125px;
	line-height: 44px;
	text-align: center;
	border-radius: 5px;
}
.setpopch :first-child {
	background-color: #e5e5e5;
	color: #a8a8a8;
}
.setpopch :last-child {
	background-color: #3fc377;
	color: white;
}
</style>
